package com.ruoyi.driver.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.driver.domain.CarownerUsecar;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.driver.service.ICarownerUsecarService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用车类型Controller
 * 
 * @author Wevon
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/driver/usecar")
public class CarownerUsecarController extends BaseController
{
    @Autowired
    private ICarownerUsecarService carownerUsecarService;

    /**
     * 查询用车类型列表
     */
    @PreAuthorize("@ss.hasPermi('driver:usecar:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarownerUsecar carownerUsecar)
    {
        startPage();
        List<CarownerUsecar> list = carownerUsecarService.selectCarownerUsecarList(carownerUsecar);
        return getDataTable(list);
    }

    /**
     * 导出用车类型列表
     */
    @PreAuthorize("@ss.hasPermi('driver:usecar:export')")
    @Log(title = "用车类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarownerUsecar carownerUsecar)
    {
        List<CarownerUsecar> list = carownerUsecarService.selectCarownerUsecarList(carownerUsecar);
        ExcelUtil<CarownerUsecar> util = new ExcelUtil<CarownerUsecar>(CarownerUsecar.class);
        util.exportExcel(response, list, "用车类型数据");
    }

    /**
     * 获取用车类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('driver:usecar:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(carownerUsecarService.selectCarownerUsecarById(id));
    }

    /**
     * 新增用车类型
     */
    @PreAuthorize("@ss.hasPermi('driver:usecar:add')")
    @Log(title = "用车类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarownerUsecar carownerUsecar)
    {
        return toAjax(carownerUsecarService.insertCarownerUsecar(carownerUsecar));
    }

    /**
     * 修改用车类型
     */
    @PreAuthorize("@ss.hasPermi('driver:usecar:edit')")
    @Log(title = "用车类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarownerUsecar carownerUsecar)
    {
        return toAjax(carownerUsecarService.updateCarownerUsecar(carownerUsecar));
    }

    /**
     * 删除用车类型
     */
    @PreAuthorize("@ss.hasPermi('driver:usecar:remove')")
    @Log(title = "用车类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carownerUsecarService.deleteCarownerUsecarByIds(ids));
    }
}
